package com.lili.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lili.controller.request.XasCouponListRequest;
import com.lili.controller.request.XasUserCouponRecordsRequest;
import com.lili.po.XasCouponList;
import com.lili.service.XasCouponService;
import com.lili.vo.MyPage;
import com.lili.vo.ResponseResult;
import com.lili.vo.XasUserCouponRecordsVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("coupon")
public class XasCouponController {
    @Autowired
    XasCouponService xasCouponService;


    @RequestMapping("xasUserCouponRecords")
    public ResponseResult xasUserCouponRecords(@RequestBody XasUserCouponRecordsRequest xasUserCouponRecordsRequest) {
        ResponseResult responseResult = new ResponseResult();
        MyPage myPage = new MyPage();
        BeanUtils.copyProperties(xasUserCouponRecordsRequest, myPage);
        IPage<XasUserCouponRecordsVo> iPage = xasCouponService.xasUserCouponRecords(xasUserCouponRecordsRequest);
        myPage.setTotal(iPage.getTotal());
        myPage.setRecords(iPage.getRecords());
        responseResult.setData(myPage);
        return responseResult;
    }


    @RequestMapping("addCoupon")
    public ResponseResult addCoupon(@RequestBody XasCouponList xasCouponList) {
        xasCouponService.addCoupon(xasCouponList);
        return new ResponseResult();
    }

    @RequestMapping("delCoupon")
    public ResponseResult delCoupon(@RequestBody XasCouponList xasCouponList) {
        xasCouponService.delCoupon(xasCouponList.getId());
        return new ResponseResult();
    }

    @RequestMapping("updateCoupon")
    public ResponseResult updateCoupon(@RequestBody XasCouponList xasCouponList) {
        xasCouponService.updateCoupon(xasCouponList);
        return new ResponseResult();
    }

    @RequestMapping("xasCouponList")
    public ResponseResult xasCouponList(@RequestBody XasCouponListRequest xasCouponListRequest) {
        ResponseResult responseResult = new ResponseResult();
        MyPage myPage = new MyPage();
        BeanUtils.copyProperties(xasCouponListRequest, myPage);
        IPage<XasCouponList> iPage = xasCouponService.xasCouponList(xasCouponListRequest);
        myPage.setTotal(iPage.getTotal());
        myPage.setRecords(iPage.getRecords());
        responseResult.setData(myPage);
        return responseResult;
    }


}
